﻿using Base.Common;
using Base.WCS.Crane;

using System;
using System.Collections.Generic;


namespace GK.WCS.Client
{
    public class CraneStatusGk : CraneStatus
    {
        public const int flag = 0b111111 << 24 + 11111111 << 16 + 11111111 << 8 + 11111111;
        public String[] index = new string[] {
"           触摸屏急停按钮故障   "      ,
"地面站急停故障"       ,
"主控柜急停故障                 "       ,
"堆垛机同巷道运行故障            "      ,
"PACK线体急停                   "      ,
"转运线体通讯故障               "       ,
"PACK线体通讯故障               "      ,
"转运线体急停                   "      ,
"触摸屏停止故障                 "       ,
"系统进入维修模式               "       ,
"安全门打开                     "      ,
"Static_19                     "      ,
"上位机wcs没有向返回任务完成信号 "       ,
"Static_17                     "      ,
"Static_1                      "      ,
"wcs急停                       "       ,
"Static_3                      "      ,
"Static_4                      "      ,
"Static_11                     "      ,
"Static_12                     "      ,
"Static_13                     "      ,
"Static_14                     "      ,
"出库站台检测有货               "       ,
"下发作业无效                   "      ,
"堆垛机与调度系统通讯故障        "       ,
"堆垛机与输送机通信故障          "      ,
"堆垛机与堆垛机通信故障          "      ,
"托盘号错                       "      ,
"托盘号信息跟踪异常              "      ,
"取货无箱                       "      ,
"双重入库                       "      ,
"控制柜使能                     "      ,
"水平变频器故障                 "       ,
"天轨变频器故障                 "       ,
"水平货叉同时动作异常            "      ,
"水平驱动异常                   "      ,
"水平天轨电机不同步              "      ,
"水平前限位开关故障              "      ,
"水平后限位开关故障              "      ,
"水平断路器供电异常              "      ,
"天轨断路器供电异常              "      ,
"水平测距仪异常                 "       ,
"水平运行反向                   "      ,
"水平前进到最大列之前            "      ,
"水平后退到最小列之后            "      ,
"Static_14                     "      ,
"Static_15                     "      ,
"Static_16                     "      ,
"水平运行位置错误               "       ,
"水平巷道识别异常               "       ,
"水平一巷道开关异常              "      ,
"水平二巷道开关异常              "      ,
"水平前减速开关故障              "      ,
"水平后减速开关故障              "      ,
"水平定位异常                   "      ,
"水平编码器故障                 "       ,
"Static_8                      "      ,
"Static_18                     "      ,
"Static_19                     "      ,
"Static_20                     "      ,
"Static_21                     "      ,
"Static_22                     "      ,
"Static_23                     "      ,
"Static_24                     "      ,
"垂直微动超时(货叉不在中位)      "       ,
"垂直变频器故障                 "       ,
"垂直前松绳开关故障              "      ,
"垂直后松绳开关故障              "      ,
"垂直前超载开关故障              "      ,
"垂直后超载开关故障              "      ,
"垂直断路器供电异常              "      ,
"垂直上限位开关故障              "      ,
"直下限位开关故障               "       ,
"垂直测距值异常                 "       ,
"垂直安全钳故障                 "       ,
"垂直启动故障                   "      ,
"垂直认址故障                   "      ,
"垂直低位过低故障               "       ,
"垂直运行方向错误故障            "      ,
"垂直高位过高故障               "       ,
"垂直运行过速故障               "       ,
"垂直限速器松绳开关故障          "      ,
"垂直限速器超速开关故障          "      ,
"垂直上最高层之上               "       ,
"垂直下最高层之下               "       ,
"Static_22                     "      ,
"Static_23                     "      ,
"Static_24                     "      ,
"垂直上限速开关故障              "      ,
"垂直下限速开关故障              "      ,
"垂直定位异常                   "      ,
"Static_28                     "      ,
"垂直左上横梁探测开关            "      ,
"垂直左下横梁探测开关            "      ,
"垂直右上横梁探测开关            "      ,
"垂直右下横梁探测开关            "      ,
"货叉断路器故障                 "       ,
"货叉变频器故障                 "       ,
"货叉单伸位编码器故障            "      ,
"货叉双伸位编码器故障            "      ,
"货叉单伸位运行超时故障          "      ,
"货叉双伸位运行超时故障          "      ,
"载货台上的货物前超长故障        "       ,
"载货台上的货物后超长故障        "       ,
"载货台上的货物左超宽故障        "       ,
"载货台上的货物右超宽故障        "       ,
"货叉左回位检测                 "       ,
"货叉右回位检测                 "       ,
"货叉前超长开关故障              "      ,
"货叉后超长开关故障              "      ,
"Static_15                     "      ,
"Static_16                     "      ,
"货叉左到位开关故障              "      ,
"货叉中位开关故障               "       ,
"货叉右到位开关故障              "      ,
"货物左超高故障                 "       ,
"货物右超高故障                 "       ,
"载货台货物检测开关故障          "      ,
"双伸位取货任务，单伸位有货      "       ,
"双伸位放货任务，单伸位有货      "       ,
"条码读错故障                   "      ,
"货叉左探测开关故障              "      ,
"货叉右探测开关故障              "      ,
"货叉左超宽开关故障              "      ,
"货叉右超宽开关故障              "      ,
"货叉左超高开关故障              "      ,
"货叉右超高开关故障              "      ,
"拨杆运行超时+U166H78U88:U205   "      ,

            };


        public CraneStatusGk() : base(0, null)
        {
        }
        public CraneStatusGk(int id) : base(id, null)
        {
        }
        public CraneStatusGk(int id, CraneStatus bs) : base(id, bs)
        {
        }
        public byte[] b;
        public int stnId;
        public override bool checkCrane()
        {
            if ((error & flag) != 0)
            {
                LoggerCommon.consol("舵机" + eId + "异常" + error);
                return false;
            }

            return craneMode == 2;
        }
        public int error;

        public int craneMode;//堆垛机模式
        public int finishFlag;//完成标志
        public int finishTaskNo;//完成任务号

        public List<String> getInf()
        {
            List<String> list = new List<string>();
            if (b == null) 
            {
                return new List<string>();
            }
            for (int i = 0; i < b.Length; i++)
            {
                byte e = b[i];
                for (int j = 0; j < 8; j++)
                {
                    if ((e & 1) == 1)
                    {
                        list.Add(index[i * 8 + j]);
                    }
                    e = (byte)(e >> 1);
                }
            }
            return list;

        }








    }
}
